package cn.mcch.investigator.observer;

import java.util.ArrayList;
import java.util.List;

public class InvestigatorObserverable {

    private static List<InvestigatorObserver> observers = new ArrayList<InvestigatorObserver>();

    public static void addObserver(InvestigatorObserver observer) {
        if (observer == null) {
            throw new NullPointerException();
        }
        if (!observers.contains(observer))
            observers.add(observer);
    }

    public static void deleteObserver(InvestigatorObserver observer) {
        observers.remove(observer);
    }

    public static void clearAllObservers() {
        observers.clear();
    }

    public static void notifyObservers(int type, Object data) {
        for (InvestigatorObserver observer : observers) {
            observer.notify(type, data);
        }
    }

}
